import {register} from '../../api/api'
import {Dispatch} from 'redux'
import {SETUSERINFO} from '../types'
export const registerAction:(data:any)=>any = (data)=>{
  return (dispatch:Dispatch)=>{
    // setTimeout(() => {
    //   let obj  = {
    //     userName:'213234',
    //     userId:'2342432424',
    //     token:'34535535',
    //     nickName:'3443563463456'
    //   }
    //   localStorage.setItem("userInfo",JSON.stringify(obj));
    //   dispatch({type:SETUSERINFO,userInfo:obj})
    // }, 1000);
    return register(data).then((userInfo:any)=>{
      console.log(userInfo)
      let obj = {
        userName:userInfo.account&&userInfo.account.userName,
        userId:userInfo.account?.id,
        token:userInfo?.token,
        nickName:userInfo.profile ? userInfo.profile.nickName : 'haha'
      }
      console.log(obj)
      localStorage.setItem("userInfo",JSON.stringify(obj));
      dispatch({type:SETUSERINFO,userInfo:obj})
    })
  }
}